package com.campus.wall.ui;

import android.widget.ListView;
import android.widget.TextView;

import com.campus.wall.R;
import com.campus.wall.adapter.SendMsgAdapter;
import com.campus.wall.base.BaseMvpActivity;
import com.campus.wall.contract.SendMsgContract;
import com.campus.wall.presenter.SendMsgPresenter;
import com.campus.wall.response.MessageResponse;
import com.self.baseutile.components.CleanableEditText;
import com.self.baseutile.components.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class SendMsgActivity extends BaseMvpActivity<SendMsgPresenter> implements SendMsgContract.View {



    @BindView(R.id.message)
    CleanableEditText message;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.listView)
    ListView listView;
    private List<MessageResponse> list=new ArrayList<>();
    private SendMsgAdapter<MessageResponse> adapter;
    @Override
    public int getLayoutId() {
        return R.layout.layout_send_msg;
    }

    @OnClick(R.id.btn_back)
    void btn_back(){
        this.finish();
    }

    @Override
    public void initView() {
        mPresenter = new SendMsgPresenter(this);
        mPresenter.attachView(this);
        MessageResponse response= (MessageResponse) this.getIntent().getSerializableExtra("entity");
        name.setText(response.getName());
        list= mPresenter.initeMess();
        adapter = new SendMsgAdapter<MessageResponse>(this, list);
        listView.setAdapter(adapter);
    }

    @OnClick(R.id.send)
    void  send(){
        if(message.getText().toString().trim().isEmpty()){
            ToastUtils.Warnshow("请输入发送的消息");
            return;
        }
        MessageResponse response=new MessageResponse();
        response.setMessage(message.getText().toString().trim());
        response.setType(1);
        message.setText("");
        list=mPresenter.send(response);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onSuccess() {

    }
}
